package com.lynn.salary.web.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.lynn.salary.entity.SystemArgument;
import com.lynn.salary.pojo.FeedBack;
import com.lynn.salary.service.ISysArgumentService;
import com.lynn.salary.util.ObjectFactory;

public class SysArgumentAction extends BaseAction {
	private ISysArgumentService sysArgumentService = (ISysArgumentService) ObjectFactory
			.getBean("sysArgumentService");
	private SystemArgument systemargument;
	private List<Map<String, Object>> typeList;
	private FeedBack feedBack;
	private String flag;

	public String execute() throws Exception {
		totalCount = sysArgumentService.totalCount();
		typeList = sysArgumentService.findArgumentByLimit(pageNum, numPerPage);
		return SUCCESS;
	}

	/*
	 * public String save() throws Exception {
	 * sysArgumentService.save(systemargument); feedBack = new FeedBack();
	 * feedBack.setStatusCode("200"); feedBack.setMessage("添加成功");
	 * feedBack.setRel("addCSDialog"); feedBack.setNavTabId("canshu");
	 * feedBack.setForwardUrl(""); feedBack.setCallbackType("closeCurrent");
	 * return "saveSuccess"; }
	 */

	public String delete() throws Exception {
		sysArgumentService.delete(deleteId);
		feedBack = new FeedBack();
		feedBack.setStatusCode("200");
		feedBack.setMessage("删除成功");
		feedBack.setRel("addCSDialog");
		feedBack.setNavTabId("canshu");
		feedBack.setForwardUrl("");
		feedBack.setCallbackType("");
		return "feedback";
	}

	public String edit() throws Exception {

		if (flag.equals("showEditPage")) {
			
			String code = systemargument.getCode();
			systemargument = sysArgumentService.getByPk(code, SystemArgument.class);
			
			return "showEditPage";
		} else if (flag.equals("update")) {
			Map<String,Object> data = new HashMap<String,Object>();
			data.put("code", systemargument.getCode());
			data.put("argValue", systemargument.getArgValue());
			sysArgumentService.update(data, SystemArgument.class);
			feedBack = new FeedBack();
			feedBack.setStatusCode("200");
			feedBack.setMessage("更新成功");
			feedBack.setRel("updateSADig");
			feedBack.setNavTabId("sysArgument");
			feedBack.setForwardUrl("");
			feedBack.setCallbackType("closeCurrent");
			return "feedback";
		}
		return "error";
	}

	public SystemArgument getSystemargument() {
		return systemargument;
	}

	public void setSystemargument(SystemArgument systemargument) {
		this.systemargument = systemargument;
	}

	public List<Map<String, Object>> getTypeList() {
		return typeList;
	}

	public void setTypeList(List<Map<String, Object>> typeList) {
		this.typeList = typeList;
	}

	public FeedBack getFeedBack() {
		return feedBack;
	}

	public void setFeedBack(FeedBack feedBack) {
		this.feedBack = feedBack;
	}

	public String getFlag() {
		return flag;
	}

	public void setFlag(String flag) {
		this.flag = flag;
	}

}
